import aio_pika
from aio_pika.pool import Pool


async def init_rabbitmq_client_pool(e_loop, rc):

    rabbitmq_url = f"amqp://{rc.username}:{rc.password}@{rc.host}/{rc.vhost}"

    async def get_connection():
        return await aio_pika.connect_robust(rabbitmq_url)

    connection_pool = Pool(get_connection, max_size=20, loop=e_loop)

    async def get_channel():
        async with connection_pool.acquire() as connection:
            return await connection.channel()

    return Pool(get_channel, max_size=20, loop=e_loop)


